package com.tbsoft.trail.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

import com.tbsoft.trail.model.PurchaseOrder;
/**
 * @desc 订单保存Dao
 * @author lizhenhua
 *
 */
@Transactional
public class PurchaseOrderDao {
	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public Session getCurrentSession() {
		return getSessionFactory().getCurrentSession();
	}
	/**
	 * @desc 订单保存
	 * @param order
	 * @return
	 */
	public Integer saveOrder(PurchaseOrder order) {
		return (Integer) getCurrentSession().save(order);
	}
	/**
	 * @desc 根据ID查询订单
	 * @param id
	 * @return
	 */
	public PurchaseOrder getOrderById(Integer id) {
		return (PurchaseOrder) getCurrentSession().get(PurchaseOrder.class, id);
	}
}
